package nowcoder.huawei;

import org.apache.tomcat.util.threads.LimitLatch;

public class TT {
    public static void main(String[] args) {
        TT tt = new TT(2);
        for (int i = 0; i < 1000; i++) {
            try {
                tt.plus();
            } catch (InterruptedException e) {

            }
        }
    }
    LimitLatch limit;

    public TT(int limit) {
        this.limit = new LimitLatch(limit);
    }

    public void plus() throws InterruptedException {
        limit.countUpOrAwait();
        System.out.println("新建线程");
        new Thread(()-> {
            try {
                Thread.sleep(1000);
                System.out.println("执行结束");
                limit.countDown();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
    }
}
